package com.blog.controller;

import com.blog.model.UserVo;
import com.blog.utils.CookieKit;
import com.blog.utils.RedisKit;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;


public class BackendController {

    private UserVo loginUser = null;

    @Resource
    private HttpServletRequest request;

    @Resource
    private HttpServletResponse response;

    @Resource
    private RedisKit redisKit;

    public UserVo getLoginUser() {

        String sessionId = CookieKit.getSessionIdFromCookie(request,response);

        if (sessionId != null) {
            Object obj = redisKit.get(sessionId);
            if (obj != null) {
                loginUser = (UserVo) obj;
            }
        }
        return loginUser;
    }
}
